// led_manager.h
#ifndef LED_MANAGER_H
#define LED_MANAGER_H

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

#define MAX_LEDS 16
#define MAX_LOCKED 16

typedef enum {
    LED_OFF,
    LED_ON,
    LED_BLINK,
    LED_FLOW,
    LED_BREATH,
    LED_BREATH_PWM,
    LED_CHANGE
} LedMode;

typedef struct {
    uint8_t pin;
    LedMode mode;
    unsigned long interval;
    uint8_t pwm_channel;
    bool privileged;
} LedConfig;

typedef void (*DigitalWriteFn)(uint8_t pin, bool level);
typedef uint32_t (*MillisFn)(void);
typedef void (*PwmSetupFn)(uint8_t pin, uint8_t channel);
typedef void (*PwmWriteFn)(uint8_t channel, uint8_t duty);
typedef void (*PwmDetachFn)(uint8_t pin);

typedef struct {
    uint8_t pin;
    LedMode mode;
    unsigned long interval;
    unsigned long lastToggle;
    bool isOn;
    uint8_t brightness;
    uint8_t pwmChannel;
    bool breathingUp;
} LedState;

void led_manager_init(DigitalWriteFn write, MillisFn millis,
                      PwmSetupFn setup, PwmWriteFn writePwm, PwmDetachFn detach);

void led_manager_add(uint8_t pin);
void led_manager_remove(uint8_t pin);
void led_manager_set_mode(LedConfig config);
LedMode led_manager_get_mode(uint8_t pin);

void led_manager_set_flow_interval(unsigned long interval);
void led_manager_set_flow_direction(bool forward);
void led_manager_lock_pins(const uint8_t* pins, size_t count);
void led_manager_unlock_pins(const uint8_t* pins, size_t count);
bool led_manager_is_locked(uint8_t pin);
void led_manager_change(uint8_t pin);
void led_manager_update(void);
LedState* led_manager_get_all(void);
int led_manager_get_count(void);
void led_manager_clean_all_mode(void);

#endif // LED_MANAGER_H
